<template>
<div>
<h1>我是孙尚香</h1>
 <button @click='sun'>孙尚香</button><br/>
 我的的年龄-{{age}}
    过去的年龄:{{oldAge}}
    现在的年龄:{{nowAge}}

    <div>
        <router-view name='sun2'/>
    </div>
    </div>
</template>

<script>
export default{
    data(){
        return{
            age:this.$route.query.age,
            oldAge:'',
            nowAge:'',
    
        }
    },
    watch:{
        age:{
            handler:function(nowAge,oldAge){
            this.oldAge = oldAge;
            this.nowAge = nowAge;
             this.$router.push({path:'/Sun/Sun2',query:{age:this.age}});
             location.reload(); //重新加载本页面
        },
        // immediate: true
        
        }
    },
    mounted(){
        // this.$router.push({path:'/Sun/Sun2',query:{age:this.age}})
    },
    methods:{
         sun(){
      this.age++;
    },
    }
}
</script>